home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / unix / make / part01 next >
Encoding:
Internet Message Format  |  1990-01-17  |  53.6 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i020: make - a re-implementation of the UNIX make utility, Part01/02
  5. Message-ID: <11027@xanth.cs.odu.edu>
  6. Date: 17 Jan 90 23:16:34 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: Olaf 'Rhialto' Seibert <U211344@HNYKUN11.BITNET>
  9. Lines: 2168
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11.  
  12. Submitted-by: Olaf 'Rhialto' Seibert <U211344@HNYKUN11.BITNET>
  13. Posting-number: Volume 90, Issue 020
  14. Archive-name: unix/make/part01
  15.  
  16. - A modified Make, the ubiquitous (sp?) one, with some bugs removed
  17.   as reported in comp.os.minix, and an extra sourcefile searching
  18.   feature. May also be useful when compiling NetHack 3.0.
  19.  
  20. Freely_Distributable=Greetings(Not_For_Any_Commercial_Purpose)->
  21.         Olaf.Seibert;
  22.  
  23. #!/bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 2)."
  30. # Contents:  Makefile README README.amiga an check.c h.h input.c
  31. #   macro.c main.c make.n reader.c rules.c
  32. # Wrapped by tadguy@xanth on Wed Jan 17 18:16:22 1990
  33. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  34. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  35.   echo shar: Will not clobber existing file \"'Makefile'\"
  36. else
  37. echo shar: Extracting \"'Makefile'\" \(230 characters\)
  38. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  39. X# Makefile for make (Amiga Aztec version for use with PDC)
  40. X
  41. XCFLAGS=-Damiga #-Dpdc
  42. XCC=cc
  43. X
  44. XOBJS = main.o make.o rules.o reader.o \
  45. X       input.o macro.o check.o
  46. X
  47. Xm:    $(OBJS)
  48. X    ln -o m $(OBJS) -lc
  49. X
  50. Xdf0:test:df1:test
  51. Xtest1:file1 file2
  52. END_OF_FILE
  53. if test 230 -ne `wc -c <'Makefile'`; then
  54.     echo shar: \"'Makefile'\" unpacked with wrong size!
  55. fi
  56. # end of 'Makefile'
  57. fi
  58. if test -f 'README' -a "${1}" != "-c" ; then 
  59.   echo shar: Will not clobber existing file \"'README'\"
  60. else
  61. echo shar: Extracting \"'README'\" \(1803 characters\)
  62. sed "s/^X//" >'README' <<'END_OF_FILE'
  63. XFollowing is a repost of the public domain 'make' that I posted
  64. Xto net.sources a couple of months ago.  I have fixed a few bugs, and
  65. Xadded some more features, and the resulting changes amounted to
  66. Xabout as much text as the whole program (hence the repost).
  67. X
  68. XFor those that missed the net.sources posting, this is a public domain
  69. Xre-implementation of the UNIX make program.  There is no manual included;
  70. Xfor documentation, refer to a UNIX manual, or the source.
  71. X
  72. XHere is a list of the changes made:
  73. X
  74. Xi)    If '-' (ignore) or '@' (silent) where used at the start
  75. X    of a command, their effect was not turned off for the following
  76. X    commands.
  77. Xii)    A special target (.SUFFIXES, .PRECIOUS) or a rule (.c.o, .a.o),
  78. X    if first in the file would be taken as the default target.
  79. X    This resulted in error messages like "Don't know how to
  80. X    make .c", because things like .SUFFIXES were being made.
  81. X    This was further complicated by ---
  82. Xiii)    Special target lines with no dependents (ie. .SUFFIXES:\n)
  83. X    were not clearing out the existing dependents like
  84. X    they should.
  85. Xiv)    Default rules could not be redefined because of the error
  86. X    checking for commands being defined twice.  Now you are
  87. X    allowed to define a target beinging with '.', having
  88. X    no dependents with commands.
  89. Xv)    The -q option didn't do the time comparison correctly,
  90. X    or clear the variable used to keep track of this.  Thus
  91. X    it didn't work very well.
  92. Xvi)    The syntax ${..} for macro's supported by UNIX make was
  93. X    not supported.
  94. Xvii)    There wuz a couple of spelling errors.
  95. Xviii)    When make checked for implicit rules on targets without
  96. X    a suffix, there were problems.  (Note: The ~ feature of
  97. X    UNIX make wasn't and still isn't supported)
  98. Xix)    The -n option did not print @ lines like it was supposed to.
  99. Xx)    :: added.  (See UNIX manual)
  100. Xxi)    $? added.  (see UNIX manual)
  101. END_OF_FILE
  102. if test 1803 -ne `wc -c <'README'`; then
  103.     echo shar: \"'README'\" unpacked with wrong size!
  104. fi
  105. # end of 'README'
  106. fi
  107. if test -f 'README.amiga' -a "${1}" != "-c" ; then 
  108.   echo shar: Will not clobber existing file \"'README.amiga'\"
  109. else
  110. echo shar: Extracting \"'README.amiga'\" \(4397 characters\)
  111. sed "s/^X//" >'README.amiga' <<'END_OF_FILE'
  112. XThis program is the public domain Make program which appeared on
  113. Xmod.sources, Volume 7, number 91.  I have ported it to the Amiga under
  114. XManx Aztec C version 3.40a.  This short document assumes you know
  115. XMake, and simply points out the Amiga specific features of the
  116. Xprogram.  The supported switches are listed in the comment block at
  117. Xthe beginning of module main.c.  I offer no apologies for the fact that
  118. XI ran the code through "indent -i4 -nfc1" on the 4.3BSD system at work
  119. Xbefore I started working on it.
  120. X   The program has been compiled under Manx Aztec C Version 3.40.
  121. XIt uses Manx's fexecv() function to execute commands and get
  122. Xtheir return value, and the Manx dos_packet() function to send an
  123. XAmigaDOS packet to the file system for touch'ing purposes.  Lattice
  124. Xrecompilers need to change these (at least).  Peculiar features
  125. Xof the Amiga version are:
  126. X
  127. X(1) The Amiga-specific sections of the code are #ifdef'd on the symbol
  128. X    amiga (note the lower case).  I endorse Fred Fish's effort to
  129. X    have system and compiler-supplied #define's in lower case to
  130. X    ensure no collisions with user-supplied ones.
  131. X(2) The file rules.c, routine makerules(), contains the definitions of
  132. X    the default built-in rules. For the Amiga, these are equivalent to
  133. X    the Makefile:
  134. X
  135. X    CC = cc
  136. X    CFLAGS =
  137. X    AS = as
  138. X    AFLAGS =
  139. X
  140. X    .c.o:
  141. X        $(CC) $(CFLAGS) $<
  142. X    .s.o:
  143. X        $(AS) $(AFLAGS) -o $@ $<
  144. X
  145. X    (indented for clarity only).  Thus, one could conceivably do:
  146. X    make CC=lc CFLAGS= AS=asm
  147. X    to run this make under Lattice C.
  148. X(3) If the file S:builtins.make exists, its contents are read in
  149. X    instead of the built-in rules defined in makerules().  Thus, you
  150. X    can use different default rules on different disks and change
  151. X    the default rules without recompiling make.
  152. X(4) A Control-D typed during execution of a command by make will cause
  153. X    an abort with exit status 1 AFTER the completion of that command.
  154. X    Control-C is an immediate abort, as you might expect.
  155. X(5) Not really Amiga specific, but worth mentioning, is that characters
  156. X    special both to the local operating system (such as : in AmigaDOS) and
  157. X    to make may be used in the makefile by preceding them with \
  158. X    to temporarily override their special meaning.  For example, to tell
  159. X    make that RAM:foo depends on AC:foo.c, write:
  160. X
  161. X    RAM\:foo : AC\:foo.c
  162. X
  163. X(6) The Aztec fexecv() function, which is used by make to execute its
  164. X    commands, only works on programs in directories stored along the
  165. X    AmigaDOS PATH, so make sure your PATH includes the appropriate
  166. X    directories.
  167. X
  168. X    Finally, I added one new feature in the non-machine-specific code:
  169. Xthe name of the makefile can be a single dash "-", in which case a
  170. Xmakefile is read from the standard input.
  171. X    About the only feature of "real" make missing here is the
  172. Xsemicolon construct which allows a pair of lines such as the .c.o:
  173. Xrule and command above to be written as one line, viz:
  174. X    .c.o: ; $(CC) $(CFLAGS) $<
  175. X
  176. XEnjoy!    Bug reports in the Amiga-specific stuff should be directed to
  177. Xme;  others should go to caret@fairlight.OZ, the author of the rest of it.
  178. XBy the way, this code is superior to the Manx-supplied make--more switches
  179. Xand a better parser;  in fact, this make will handle the Makefile for
  180. XMicroGnuEmacs while Manx make chokes on the ln command.
  181. X
  182. X                Steve Walton
  183. X                ametek!walton@csvax.caltech.edu (ARPA)
  184. X                WALTON@CALTECH (BITNET)
  185. X                ...!ucbvax!sun!megatest!ametek!walton
  186. X
  187. XSome notes by Olaf Seibert, KosmoSoft:
  188. X
  189. XI adapted this version of make to PDC, and enhanced it a little. In
  190. Xparticular, if a line end with a backslash, the following newline and
  191. Xleading white space of the next line are now ignored. Previously, the
  192. Xnewline was merely turned into a space. Also, comparison of filenames now
  193. Xis case-insignificant. Makefiles need not be internally consistent in the
  194. Xcase of filenames. Also, the builtin rules are slightly different, for use
  195. Xwith PDC.
  196. X
  197. X    CC = ccx -c
  198. X    CFLAGS =
  199. X    AS = ccx -c
  200. X    AFLAGS =
  201. X
  202. X    .c.o:
  203. X        $(CC) $(CFLAGS) $<
  204. X    .s.o:
  205. X        $(AS) $(AFLAGS) $<
  206. X
  207. X                /*OIS*0.80*/
  208. X
  209. XI took out the \: feature, which worked only in target names, and not in
  210. Xprerequisite files. Instead, I added a more rational interpretation of
  211. Xcolons. There is now at most one colon possible in a target name, which may
  212. Xnot contain any spaces.
  213. X
  214. XI incorporared a few bug fixes relating to $< and $*, from the minix newsgroup.
  215. XI added a new feature: the .PATH special target. See manual.
  216. X
  217. END_OF_FILE
  218. if test 4397 -ne `wc -c <'README.amiga'`; then
  219.     echo shar: \"'README.amiga'\" unpacked with wrong size!
  220. fi
  221. # end of 'README.amiga'
  222. fi
  223. if test -f 'an' -a "${1}" != "-c" ; then 
  224.   echo shar: Will not clobber existing file \"'an'\"
  225. else
  226. echo shar: Extracting \"'an'\" \(2210 characters\)
  227. sed "s/^X//" >'an' <<'END_OF_FILE'
  228. X.*
  229. X.*    Macro package for NRO in KosmoSoft version
  230. X.*
  231. X.nr h 5      @" header indent
  232. X.nr i 10     @" normal text indent
  233. X.nr s @ni-@nh     @" section heading indent (to the LEFT)
  234. X.*
  235. X.de TH
  236. X.in @nh;.rm 80-@nh;.he |$0($1)|$2|$0($1)|
  237. X.fo |$3|-#-|$4|
  238. X.in @ni;.rm 80-@ni
  239. X.ta +0 +5
  240. X.en
  241. X.*  Paragraph
  242. X.de PP
  243. X.sp 1;.ne 2;.ti +5
  244. X.en
  245. X.*  Bulleted Paragraph. Needs .RE after last para.
  246. X.*  Must be last on line. Relies on first tab stop.
  247. X.de BP
  248. X.br;.in @ni+5;.ti -3;o@t@@
  249. X.en
  250. X.*  Section Heading
  251. X.de SH
  252. X.sp 1;.ne 3;.ti -@@ns;.bo "$0 $1 $2 $3 $4 $6 $6 $7 $8 $9
  253. X.br
  254. X.en
  255. X.*  SubSection
  256. X.de SS
  257. X.br;.ne 2;.ti -@@ns+1/2;$0 $1 $2 $3 $4 $5 $6 $7 $8 $9
  258. X.br
  259. X.en
  260. X.*  Relative indent Start
  261. X.de RS
  262. X.in +0$0
  263. X.en
  264. X.*  Relative indent End
  265. X.de RE
  266. X.in @ni
  267. X.en
  268. X.*  Italics
  269. X.de I
  270. X.it 1
  271. X$0 $1 $2 $3 $4 $5 $6 $7 $8 $9
  272. X.en
  273. X.*  Bold
  274. X.de B
  275. X.bo 1
  276. X$0 $1 $2 $3 $4 $5 $6 $7 $8 $9
  277. X.en
  278. X.*  Underline
  279. X.de U
  280. X.ul 1
  281. X$0 $1 $2 $3 $4 $5 $6 $7 $8 $9
  282. X.en
  283. X.*  UC
  284. X.de UC
  285. X.*  Empty
  286. X.en
  287. X.*  Italics and Roman
  288. X.de IR
  289. X.if !''$0' .it "$0
  290. X.if !''$1' $1
  291. X.if !''$2' .it "$2
  292. X.if !''$3' $3
  293. X.if !''$4' .it "$4
  294. X.if !''$5' $5
  295. X.if !''$6' .it "$6
  296. X.if !''$7' $7
  297. X.if !''$8' .it "$8
  298. X.if !''$9' $9
  299. X.en
  300. X.*  Roman and Italic
  301. X.de RI
  302. X.if !''$0' $0
  303. X.if !''$1' .it "$1
  304. X.if !''$2' $2
  305. X.if !''$3' .it "$3
  306. X.if !''$4' $4
  307. X.if !''$5' .it "$5
  308. X.if !''$6' $6
  309. X.if !''$7' .it "$7
  310. X.if !''$8' $8
  311. X.if !''$9' .it "$9
  312. X.en
  313. X.*  Bold and Roman
  314. X.de BR
  315. X.if !''$0' .bo "$0
  316. X.if !''$1' $1
  317. X.if !''$2' .bo "$2
  318. X.if !''$3' $3
  319. X.if !''$4' .bo "$4
  320. X.if !''$5' $5
  321. X.if !''$6' .bo "$6
  322. X.if !''$7' $7
  323. X.if !''$8' .bo "$8
  324. X.if !''$9' $9
  325. X.en
  326. X.*  Bold and Italic
  327. X.de BI
  328. X.if !''$0' .bo "$0
  329. X.if !''$1' .it "$1
  330. X.if !''$2' .bo "$2
  331. X.if !''$3' .it "$3
  332. X.if !''$4' .bo "$4
  333. X.if !''$5' .it "$5
  334. X.if !''$6' .bo "$6
  335. X.if !''$7' .it "$7
  336. X.if !''$8' .bo "$8
  337. X.if !''$9' .it "$9
  338. X.en
  339. X.*  Italic and Bold
  340. X.de IB
  341. X.if !''$0' .it "$0
  342. X.if !''$1' .bo "$1
  343. X.if !''$2' .it "$2
  344. X.if !''$3' .bo "$3
  345. X.if !''$4' .it "$4
  346. X.if !''$5' .bo "$5
  347. X.if !''$6' .it "$6
  348. X.if !''$7' .bo "$7
  349. X.if !''$8' .it "$8
  350. X.if !''$9' .bo "$9
  351. X.en
  352. X.*  Italic and Roman
  353. X.de IR
  354. X.if !''$0' .it "$0
  355. X.if !''$1' $1
  356. X.if !''$2' .it "$2
  357. X.if !''$3' $3
  358. X.if !''$4' .it "$4
  359. X.if !''$5' $5
  360. X.if !''$6' .it "$6
  361. X.if !''$7' $7
  362. X.if !''$8' .it "$8
  363. X.if !''$9' $9
  364. X.en
  365. X.*  SMall, do nothing
  366. X.de SM
  367. X$0 $1 $2 $3 $4 $5 $6 $7 $8 $9
  368. X.en
  369. END_OF_FILE
  370. if test 2210 -ne `wc -c <'an'`; then
  371.     echo shar: \"'an'\" unpacked with wrong size!
  372. fi
  373. # end of 'an'
  374. fi
  375. if test -f 'check.c' -a "${1}" != "-c" ; then 
  376.   echo shar: Will not clobber existing file \"'check.c'\"
  377. else
  378. echo shar: Extracting \"'check.c'\" \(2152 characters\)
  379. sed "s/^X//" >'check.c' <<'END_OF_FILE'
  380. X/*
  381. X *    Check structures for make.
  382. X */
  383. X
  384. X#include <stdio.h>
  385. X#include "h.h"
  386. X
  387. X
  388. X/*
  389. X *    Prints out the structures as defined in memory.  Good for check
  390. X *    that you make file does what you want (and for debugging make).
  391. X */
  392. Xvoid
  393. Xprt()
  394. X{
  395. X    register struct name *np;
  396. X    register struct depend *dp;
  397. X    register struct line *lp;
  398. X    register struct cmd *cp;
  399. X    register struct macro *mp;
  400. X
  401. X
  402. X    for (mp = macrohead; mp; mp = mp->m_next)
  403. X    fprintf(stderr, "%s = %s\n", mp->m_name, mp->m_val);
  404. X
  405. X    fputc('\n', stderr);
  406. X
  407. X    for (np = namehead.n_next; np; np = np->n_next) {
  408. X    if (np->n_flag & N_DOUBLE)
  409. X        fprintf(stderr, "%s::\n", np->n_name);
  410. X    else
  411. X        fprintf(stderr, "%s:\n", np->n_name);
  412. X    if (np == firstname)
  413. X        fprintf(stderr, "(MAIN NAME)\n");
  414. X    for (lp = np->n_line; lp; lp = lp->l_next) {
  415. X        fputc(':', stderr);
  416. X        for (dp = lp->l_dep; dp; dp = dp->d_next)
  417. X        fprintf(stderr, " %s", dp->d_name->n_name);
  418. X        fputc('\n', stderr);
  419. X
  420. X        for (cp = lp->l_cmd; cp; cp = cp->c_next)
  421. X#ifdef os9
  422. X        fprintf(stderr, "-   %s\n", cp->c_cmd);
  423. X#else
  424. X        fprintf(stderr, "-\t%s\n", cp->c_cmd);
  425. X#endif
  426. X        fputc('\n', stderr);
  427. X    }
  428. X    fputc('\n', stderr);
  429. X    }
  430. X}
  431. X
  432. X
  433. X/*
  434. X *    Recursive routine that does the actual checking.
  435. X */
  436. Xvoid
  437. Xcheck(np)
  438. X    struct name    *np;
  439. X{
  440. X    register struct depend *dp;
  441. X    register struct line *lp;
  442. X
  443. X
  444. X    if (np->n_flag & N_MARK)
  445. X    fatal("Circular dependency from %s", np->n_name);
  446. X
  447. X    np->n_flag |= N_MARK;
  448. X
  449. X    for (lp = np->n_line; lp; lp = lp->l_next)
  450. X    for (dp = lp->l_dep; dp; dp = dp->d_next)
  451. X        check(dp->d_name);
  452. X
  453. X    np->n_flag &= ~N_MARK;
  454. X}
  455. X
  456. X
  457. X/*
  458. X *    Look for circular dependancies.
  459. X *    ie.
  460. X *        a: b
  461. X *        b: a
  462. X *    is a circular dep
  463. X */
  464. Xvoid
  465. Xcirch()
  466. X{
  467. X    register struct name *np;
  468. X
  469. X
  470. X    for (np = namehead.n_next; np; np = np->n_next)
  471. X    check(np);
  472. X}
  473. X
  474. X
  475. X/*
  476. X *    Check the target .PRECIOUS, and mark its dependentd as precious
  477. X */
  478. Xvoid
  479. Xprecious()
  480. X{
  481. X    register struct depend *dp;
  482. X    register struct line *lp;
  483. X    register struct name *np;
  484. X
  485. X
  486. X    if (!((np = newname(".PRECIOUS"))->n_flag & N_TARG))
  487. X    return;
  488. X
  489. X    for (lp = np->n_line; lp; lp = lp->l_next)
  490. X    for (dp = lp->l_dep; dp; dp = dp->d_next)
  491. X        dp->d_name->n_flag |= N_PREC;
  492. X}
  493. END_OF_FILE
  494. if test 2152 -ne `wc -c <'check.c'`; then
  495.     echo shar: \"'check.c'\" unpacked with wrong size!
  496. fi
  497. # end of 'check.c'
  498. fi
  499. if test -f 'h.h' -a "${1}" != "-c" ; then 
  500.   echo shar: Will not clobber existing file \"'h.h'\"
  501. else
  502. echo shar: Extracting \"'h.h'\" \(2546 characters\)
  503. sed "s/^X//" >'h.h' <<'END_OF_FILE'
  504. X/*
  505. X *    Include header for make
  506. X */
  507. X
  508. X
  509. X#ifndef uchar
  510. X#ifdef os9
  511. X#define uchar        char
  512. X#define void        int
  513. X#define fputc        putc
  514. X#else
  515. X#define uchar        unsigned char
  516. X#endif
  517. X#endif
  518. X
  519. X#define bool        uchar
  520. X#define time_t        long
  521. X#define TRUE        (1)
  522. X#define FALSE        (0)
  523. X#define max(a,b)    ((a)>(b)?(a):(b))
  524. X
  525. X#define DEFN1        "makefile"      /* Default names  */
  526. X#ifdef unix
  527. X#define DEFN2        "Makefile"
  528. X#endif
  529. X#ifdef eon
  530. X#define DEFN2        "Makefile"
  531. X#endif
  532. X
  533. X#ifdef amiga
  534. X#define strcmp        stricmp
  535. X#endif
  536. X
  537. X/* os9 is case insensitive */
  538. X
  539. X#define LZ        (1024)    /* Line size  */
  540. X
  541. X
  542. X
  543. X/*
  544. X *    A name.  This represents a file, either to be made, or existant
  545. X */
  546. X
  547. Xstruct name {
  548. X    struct name    *n_next;    /* Next in the list of names */
  549. X    char       *n_name;    /* Called */
  550. X    struct line    *n_line;    /* Dependencies */
  551. X    time_t        n_time;    /* Modify time of this name */
  552. X    uchar        n_flag;    /* Info about the name */
  553. X};
  554. X
  555. X#define N_MARK        0x01    /* For cycle check */
  556. X#define N_DONE        0x02    /* Name looked at */
  557. X#define N_TARG        0x04    /* Name is a target */
  558. X#define N_PREC        0x08    /* Target is precious */
  559. X#define N_DOUBLE    0x10    /* Double colon target */
  560. X
  561. X/*
  562. X *    Definition of a target line.
  563. X */
  564. Xstruct line {
  565. X    struct line    *l_next;    /* Next line (for ::) */
  566. X    struct depend  *l_dep;    /* Dependents for this line */
  567. X    struct cmd       *l_cmd;    /* Commands for this line */
  568. X};
  569. X
  570. X
  571. X/*
  572. X *    List of dependents for a line
  573. X */
  574. Xstruct depend {
  575. X    struct depend  *d_next;    /* Next dependent */
  576. X    struct name    *d_name;    /* Name of dependent */
  577. X};
  578. X
  579. X
  580. X/*
  581. X *    Commands for a line
  582. X */
  583. Xstruct cmd {
  584. X    struct cmd       *c_next;    /* Next command line */
  585. X    char       *c_cmd;    /* Command line */
  586. X};
  587. X
  588. X
  589. X/*
  590. X *    Macro storage
  591. X */
  592. Xstruct macro {
  593. X    struct macro   *m_next;    /* Next variable */
  594. X    char       *m_name;    /* Called ... */
  595. X    char       *m_val;    /* Its value */
  596. X    uchar        m_flag;    /* Infinite loop check */
  597. X};
  598. X
  599. Xextern char    *myname;
  600. Xextern struct name namehead;
  601. Xextern struct macro *macrohead;
  602. Xextern struct name *firstname;
  603. Xextern bool    silent;
  604. Xextern bool    ignore;
  605. Xextern bool    rules;
  606. Xextern bool    dotouch;
  607. Xextern bool    quest;
  608. Xextern bool    domake;
  609. Xextern char    str1[];
  610. Xextern char    str2[];
  611. Xextern int    lineno;
  612. X
  613. Xchar           *fgets();
  614. Xchar           *index();
  615. Xchar           *rindex();
  616. Xchar           *malloc();
  617. Xextern int    errno;
  618. X
  619. Xchar           *getmacro();
  620. Xstruct macro   *setmacro();
  621. Xvoid        input();
  622. Xvoid        error();
  623. Xvoid        fatal();
  624. Xint        make();
  625. Xstruct name    *newname();
  626. Xstruct depend  *newdep();
  627. Xstruct cmd     *newcmd();
  628. Xvoid        newline();
  629. Xchar           *suffix();
  630. Xvoid        touch();
  631. Xvoid        makerules();
  632. Xchar           *gettok();
  633. Xvoid        precious();
  634. END_OF_FILE
  635. if test 2546 -ne `wc -c <'h.h'`; then
  636.     echo shar: \"'h.h'\" unpacked with wrong size!
  637. fi
  638. # end of 'h.h'
  639. fi
  640. if test -f 'input.c' -a "${1}" != "-c" ; then 
  641.   echo shar: Will not clobber existing file \"'input.c'\"
  642. else
  643. echo shar: Extracting \"'input.c'\" \(7435 characters\)
  644. sed "s/^X//" >'input.c' <<'END_OF_FILE'
  645. X/*
  646. X *    Parse a makefile
  647. X */
  648. X
  649. X
  650. X#include <stdio.h>
  651. X#include <ctype.h>
  652. X#include "h.h"
  653. X
  654. X
  655. Xstruct name    namehead;
  656. Xstruct name    *firstname;
  657. X
  658. Xchar        str1[LZ];    /* General store  */
  659. Xchar        str2[LZ];
  660. X
  661. X
  662. X/*
  663. X *    Intern a name.    Return a pointer to the name struct
  664. X */
  665. Xstruct name    *
  666. Xnewname(name)
  667. X    char       *name;
  668. X{
  669. X    register struct name *rp;
  670. X    register struct name *rrp;
  671. X    register char  *cp;
  672. X
  673. X
  674. X    for
  675. X    (
  676. X     rp = namehead.n_next, rrp = &namehead;
  677. X     rp;
  678. X     rp = rp->n_next, rrp = rrp->n_next
  679. X    )
  680. X    if (strcmp(name, rp->n_name) == 0)
  681. X        return rp;
  682. X
  683. X    if ((rp = (struct name *) malloc(sizeof(struct name)))
  684. X    == (struct name *) 0)
  685. X    fatal("No memory for name");
  686. X    rrp->n_next = rp;
  687. X    rp->n_next = (struct name *) 0;
  688. X    if ((cp = malloc((unsigned) strlen(name) + 1)) == (char *) 0)
  689. X    fatal("No memory for name");
  690. X    strcpy(cp, name);
  691. X    rp->n_name = cp;
  692. X    rp->n_line = (struct line *) 0;
  693. X    rp->n_time = (time_t) 0;
  694. X    rp->n_flag = 0;
  695. X
  696. X    return rp;
  697. X}
  698. X
  699. X/*
  700. X *  Delete the last created name.
  701. X */
  702. X
  703. Xdelname(np)
  704. Xstruct name *np;
  705. X{
  706. X    if (namehead.n_next == np) {
  707. X    namehead.n_next = np->n_next;
  708. X    free(np);
  709. X    }
  710. X}
  711. X
  712. X/*
  713. X *    Add a dependant to the end of the supplied list of dependants.
  714. X *    Return the new head pointer for that list.
  715. X */
  716. Xstruct depend  *
  717. Xnewdep(np, dp)
  718. X    struct name    *np;
  719. X    struct depend  *dp;
  720. X{
  721. X    register struct depend *rp;
  722. X    register struct depend *rrp;
  723. X
  724. X
  725. X    if ((rp = (struct depend *) malloc(sizeof(struct depend)))
  726. X    == (struct depend *) 0)
  727. X    fatal("No memory for dependant");
  728. X    rp->d_next = (struct depend *) 0;
  729. X    rp->d_name = np;
  730. X
  731. X    if (dp == (struct depend *) 0)
  732. X    return rp;
  733. X
  734. X    for (rrp = dp; rrp->d_next; rrp = rrp->d_next);
  735. X
  736. X    rrp->d_next = rp;
  737. X
  738. X    return dp;
  739. X}
  740. X
  741. X
  742. X/*
  743. X *    Add a command to the end of the supplied list of commands.
  744. X *    Return the new head pointer for that list.
  745. X */
  746. Xstruct cmd     *
  747. Xnewcmd(str, cp)
  748. X    char       *str;
  749. X    struct cmd       *cp;
  750. X{
  751. X    register struct cmd *rp;
  752. X    register struct cmd *rrp;
  753. X    register char  *rcp;
  754. X
  755. X
  756. X    if (rcp = rindex(str, '\n'))
  757. X    *rcp = '\0';            /* Loose newline  */
  758. X
  759. X    while (isspace(*str))
  760. X    str++;
  761. X
  762. X    if (*str == '\0')           /* If nothing left, the exit  */
  763. X    return (struct cmd *) 0;
  764. X
  765. X    if ((rp = (struct cmd *) malloc(sizeof(struct cmd)))
  766. X    == (struct cmd *) 0)
  767. X    fatal("No memory for command");
  768. X    rp->c_next = (struct cmd *) 0;
  769. X    if ((rcp = malloc((unsigned) strlen(str) + 1)) == (char *) 0)
  770. X    fatal("No memory for command");
  771. X    strcpy(rcp, str);
  772. X    rp->c_cmd = rcp;
  773. X
  774. X    if (cp == (struct cmd *) 0)
  775. X    return rp;
  776. X
  777. X    for (rrp = cp; rrp->c_next; rrp = rrp->c_next);
  778. X
  779. X    rrp->c_next = rp;
  780. X
  781. X    return cp;
  782. X}
  783. X
  784. X
  785. X/*
  786. X *    Add a new 'line' of stuff to a target.  This check to see
  787. X *    if commands already exist for the target.  If flag is set,
  788. X *    the line is a double colon target.
  789. X *
  790. X *    Kludges:
  791. X *    i)  If the new name begins with a '.', and there are no dependents,
  792. X *        then the target must cease to be a target.    This is for .SUFFIXES.
  793. X *    ii) If the new name begins with a '.', with no dependents and has
  794. X *        commands, then replace the current commands.  This is for
  795. X *        redefining commands for a default rule.
  796. X *    Neither of these free the space used by dependents or commands,
  797. X *    since they could be used by another target.
  798. X */
  799. Xvoid
  800. Xnewline(np, dp, cp, flag)
  801. X    struct name    *np;
  802. X    struct depend  *dp;
  803. X    struct cmd       *cp;
  804. X    bool        flag;
  805. X{
  806. X    bool        hascmds = FALSE;    /* Target has commands    */
  807. X    register struct line *rp;
  808. X    register struct line *rrp;
  809. X
  810. X
  811. X    /* Handle the .SUFFIXES case */
  812. X    if (np->n_name[0] == '.' && !dp && !cp) {
  813. X    for (rp = np->n_line; rp; rp = rrp) {
  814. X        rrp = rp->l_next;
  815. X        free((char *) rp);
  816. X    }
  817. X    np->n_line = (struct line *) 0;
  818. X    np->n_flag &= ~N_TARG;
  819. X    return;
  820. X    }
  821. X    /* This loop must happen since rrp is used later. */
  822. X    for
  823. X    (
  824. X     rp = np->n_line, rrp = (struct line *) 0;
  825. X     rp;
  826. X     rrp = rp, rp = rp->l_next
  827. X    )
  828. X    if (rp->l_cmd)
  829. X        hascmds = TRUE;
  830. X
  831. X    if (hascmds && cp && !(np->n_flag & N_DOUBLE))
  832. X    /* Handle the implicit rules redefinition case */
  833. X    if (np->n_name[0] == '.' && dp == (struct depend *) 0) {
  834. X        np->n_line->l_cmd = cp;
  835. X        return;
  836. X    } else
  837. X        error("Commands defined twice for target %s", np->n_name);
  838. X    if (np->n_flag & N_TARG)
  839. X    if (!(np->n_flag & N_DOUBLE) != !flag)  /* like xor */
  840. X        error("Inconsistent rules for target %s", np->n_name);
  841. X
  842. X    if ((rp = (struct line *) malloc(sizeof(struct line)))
  843. X    == (struct line *) 0)
  844. X    fatal("No memory for line");
  845. X    rp->l_next = (struct line *) 0;
  846. X    rp->l_dep = dp;
  847. X    rp->l_cmd = cp;
  848. X
  849. X    if (rrp)
  850. X    rrp->l_next = rp;
  851. X    else
  852. X    np->n_line = rp;
  853. X
  854. X    np->n_flag |= N_TARG;
  855. X    if (flag)
  856. X    np->n_flag |= N_DOUBLE;
  857. X}
  858. X
  859. X
  860. X/*
  861. X *    Parse input from the makefile, and construct a tree structure
  862. X *    of it.
  863. X */
  864. Xvoid
  865. Xinput(fd)
  866. X    FILE       *fd;
  867. X{
  868. X    char       *p;        /* General  */
  869. X    char       *q;
  870. X    struct name    *np;
  871. X    struct depend  *dp;
  872. X    struct cmd       *cp;
  873. X    bool        dbl, getline();
  874. X
  875. X
  876. X    if (getline(str1, fd))      /* Read the first line  */
  877. X    return;
  878. X
  879. X    for (;;) {
  880. X    if (str1[0] == '\t' || str1[0] == ' ')  /* Rules without targets  */
  881. X        error("Rules not allowed here");
  882. X
  883. X    p = str1;
  884. X
  885. X    while (isspace(*p))     /* Find first target  */
  886. X        p++;
  887. X
  888. X    while (((q = index(p, '=')) != (char *) 0) &&
  889. X           (p != q) && (q[-1] == '\\')) {   /* Find value */
  890. X        register char  *a;
  891. X
  892. X        a = q - 1;        /* Del \ chr; move rest back  */
  893. X        p = q;
  894. X        while (*a++ = *q++);
  895. X    }
  896. X
  897. X    if (q != (char *) 0) {
  898. X        register char  *a;
  899. X
  900. X        *q++ = '\0';        /* Separate name and val  */
  901. X        while (isspace(*q))
  902. X        q++;
  903. X        if (p = rindex(q, '\n'))
  904. X        *p = '\0';
  905. X
  906. X        p = str1;
  907. X        if ((a = gettok(&p)) == (char *) 0)
  908. X        error("No macro name");
  909. X
  910. X        setmacro(a, q);
  911. X
  912. X        if (getline(str1, fd))
  913. X        return;
  914. X        continue;
  915. X    }
  916. X    expand(str1);
  917. X    p = str1;
  918. X
  919. X#if 0
  920. X    while (((q = index(p, ':')) != (char *) 0) &&
  921. X           (p != q) && (q[-1] == '\\')) {   /* Find dependents  */
  922. X        register char  *a;
  923. X
  924. X        a = q - 1;        /* Del \ chr; move rest back  */
  925. X        p = q;
  926. X        while (*a++ = *q++);
  927. X    }
  928. X#else
  929. X    q = index(p, ':');
  930. X#endif
  931. X
  932. X    if (q == (char *) 0)
  933. X        error("No targets provided");
  934. X
  935. X    /* Added by OIS to allow at most one : in target names */
  936. X
  937. X    {
  938. X        register char *a = q;
  939. X
  940. X        while (*++a) {
  941. X        if (*a == ' ' || *a == '\t') {
  942. X            /* Found no more colons. Must have been first one. */
  943. X            break;
  944. X        }
  945. X        if (*a == ':') {
  946. X            /* Found second colon. This must be the separator. */
  947. X            if (a != q+1)   /* No double colon */
  948. X            q = a;
  949. X            break;
  950. X        }
  951. X        }
  952. X    }
  953. X
  954. X    *q++ = '\0';            /* Separate targets and dependents  */
  955. X
  956. X    if (*q == ':') {        /* Double colon */
  957. X        dbl = 1;
  958. X        q++;
  959. X    } else
  960. X        dbl = 0;
  961. X
  962. X    for (dp = (struct depend *) 0; ((p = gettok(&q)) != (char *) 0);)
  963. X        /* get list of dep's */
  964. X    {
  965. X        np = newname(p);    /* Intern name  */
  966. X        dp = newdep(np, dp);/* Add to dep list */
  967. X    }
  968. X
  969. X    *((q = str1) + strlen(str1) + 1) = '\0';
  970. X    /* Need two nulls for gettok (Remember separation)  */
  971. X
  972. X    cp = (struct cmd *) 0;
  973. X    if (getline(str2, fd) == FALSE) {       /* Get commands  */
  974. X        while (str2[0] == '\t' || str2[0] == ' ') { /*OIS*0.80*/
  975. X        cp = newcmd(&str2[0], cp);
  976. X        if (getline(str2, fd))
  977. X            break;
  978. X        }
  979. X    }
  980. X    while ((p = gettok(&q)) != (char *) 0) {        /* Get list of targ's */
  981. X        np = newname(p);    /* Intern name  */
  982. X        newline(np, dp, cp, dbl);
  983. X        if (!firstname && p[0] != '.')
  984. X        firstname = np;
  985. X    }
  986. X
  987. X    if (feof(fd))           /* EOF?  */
  988. X        return;
  989. X
  990. X    strcpy(str1, str2);
  991. X    }
  992. X}
  993. END_OF_FILE
  994. if test 7435 -ne `wc -c <'input.c'`; then
  995.     echo shar: \"'input.c'\" unpacked with wrong size!
  996. fi
  997. # end of 'input.c'
  998. fi
  999. if test -f 'macro.c' -a "${1}" != "-c" ; then 
  1000.   echo shar: Will not clobber existing file \"'macro.c'\"
  1001. else
  1002. echo shar: Extracting \"'macro.c'\" \(2582 characters\)
  1003. sed "s/^X//" >'macro.c' <<'END_OF_FILE'
  1004. X/*
  1005. X *    Macro control for make
  1006. X */
  1007. X
  1008. X
  1009. X#include "h.h"
  1010. X#undef strcmp    /*OIS*0.80*/
  1011. X
  1012. Xstruct macro   *macrohead;
  1013. X
  1014. X
  1015. Xstruct macro   *
  1016. Xgetmp(name)
  1017. X    register char      *name;
  1018. X{
  1019. X    register struct macro *rp;
  1020. X
  1021. X    for (rp = macrohead; rp; rp = rp->m_next)
  1022. X    if (strcmp(name, rp->m_name) == 0)
  1023. X        return rp;
  1024. X    return (struct macro *) 0;
  1025. X}
  1026. X
  1027. X
  1028. Xchar           *
  1029. Xgetmacro(name)
  1030. X    char       *name;
  1031. X{
  1032. X    struct macro   *mp;
  1033. X
  1034. X    if (mp = getmp(name))
  1035. X    return mp->m_val;
  1036. X    else
  1037. X    return "";
  1038. X}
  1039. X
  1040. X
  1041. Xstruct macro   *
  1042. Xsetmacro(name, val)
  1043. X    char       *name;
  1044. X    char       *val;
  1045. X{
  1046. X    register struct macro *rp;
  1047. X    register char  *cp;
  1048. X
  1049. X
  1050. X    /* Replace macro definition if it exists  */
  1051. X    for (rp = macrohead; rp; rp = rp->m_next)
  1052. X    if (strcmp(name, rp->m_name) == 0) {
  1053. X        free(rp->m_val);    /* Free space from old    */
  1054. X        break;
  1055. X    }
  1056. X    if (!rp) {            /* If not defined, allocate space for new  */
  1057. X    if ((rp = (struct macro *) malloc(sizeof(struct macro)))
  1058. X        == (struct macro *) 0)
  1059. X        fatal("No memory for macro");
  1060. X
  1061. X    rp->m_next = macrohead;
  1062. X    macrohead = rp;
  1063. X    rp->m_flag = FALSE;
  1064. X
  1065. X    if ((cp = malloc((unsigned) strlen(name) + 1)) == (char *) 0)
  1066. X        fatal("No memory for macro");
  1067. X    strcpy(cp, name);
  1068. X    rp->m_name = cp;
  1069. X    }
  1070. X    if ((cp = malloc((unsigned) strlen(val) + 1)) == (char *) 0)
  1071. X    fatal("No memory for macro");
  1072. X    strcpy(cp, val);        /* Copy in new value  */
  1073. X    rp->m_val = cp;
  1074. X
  1075. X    return rp;
  1076. X}
  1077. X
  1078. X
  1079. X/*
  1080. X *    Do the dirty work for expand
  1081. X */
  1082. Xvoid
  1083. Xdoexp(to, from, len, buf)
  1084. X    char      **to;
  1085. X    char       *from;
  1086. X    int        *len;
  1087. X    char       *buf;
  1088. X{
  1089. X    register char  *rp;
  1090. X    register char  *p;
  1091. X    register char  *q;
  1092. X    register struct macro *mp;
  1093. X
  1094. X
  1095. X    rp = from;
  1096. X    p = *to;
  1097. X    while (*rp) {
  1098. X    if (*rp != '$') {
  1099. X        *p++ = *rp++;
  1100. X        (*len)--;
  1101. X    } else {
  1102. X        q = buf;
  1103. X        if (*++rp == '{')
  1104. X        while (*++rp && *rp != '}')
  1105. X            *q++ = *rp;
  1106. X        else if (*rp == '(')
  1107. X        while (*++rp && *rp != ')')
  1108. X            *q++ = *rp;
  1109. X        else if (!*rp) {
  1110. X        *p++ = '$';
  1111. X        break;
  1112. X        } else
  1113. X        *q++ = *rp;
  1114. X        *q = '\0';
  1115. X        if (*rp)
  1116. X        rp++;
  1117. X        if (!(mp = getmp(buf)))
  1118. X        mp = setmacro(buf, "");
  1119. X        if (mp->m_flag)
  1120. X        fatal("Infinitely recursive macro %s", mp->m_name);
  1121. X        mp->m_flag = TRUE;
  1122. X        *to = p;
  1123. X        doexp(to, mp->m_val, len, buf);
  1124. X        p = *to;
  1125. X        mp->m_flag = FALSE;
  1126. X    }
  1127. X    if (*len <= 0)
  1128. X        error("Expanded line too long");    /*OIS*0.80*/
  1129. X    }
  1130. X    *p = '\0';
  1131. X    *to = p;
  1132. X}
  1133. X
  1134. X
  1135. X/*
  1136. X *    Expand any macros in str.
  1137. X */
  1138. Xvoid
  1139. Xexpand(str)
  1140. X    char       *str;
  1141. X{
  1142. X    static char     a[LZ];
  1143. X    static char     b[LZ];
  1144. X    char       *p = str;
  1145. X    int         len = LZ - 1;
  1146. X
  1147. X    strcpy(a, str);
  1148. X    doexp(&p, a, &len, b);
  1149. X}
  1150. END_OF_FILE
  1151. if test 2582 -ne `wc -c <'macro.c'`; then
  1152.     echo shar: \"'macro.c'\" unpacked with wrong size!
  1153. fi
  1154. # end of 'macro.c'
  1155. fi
  1156. if test -f 'main.c' -a "${1}" != "-c" ; then 
  1157.   echo shar: Will not clobber existing file \"'main.c'\"
  1158. else
  1159. echo shar: Extracting \"'main.c'\" \(5539 characters\)
  1160. sed "s/^X//" >'main.c' <<'END_OF_FILE'
  1161. X/*
  1162. X *    make [-f makefile] [-ins] [target(s) ...]
  1163. X *
  1164. X *    (Better than EON mk but not quite as good as UNIX make)
  1165. X *
  1166. X *    -f makefile name
  1167. X *    -i ignore exit status
  1168. X *    -n Pretend to make
  1169. X *    -p Print all macros & targets
  1170. X *    -q Question up-to-dateness of target.  Return exit status 1 if not
  1171. X *    -r Don't not use inbuilt rules
  1172. X *    -s Make silently
  1173. X *    -t Touch files instead of making them
  1174. X *    -m Change memory requirements (EON only)
  1175. X */
  1176. X
  1177. X#include <stdio.h>
  1178. X#include "h.h"
  1179. X
  1180. X#ifdef unix
  1181. X#include <sys/errno.h>
  1182. X#endif
  1183. X#ifdef eon
  1184. X#include <sys/err.h>
  1185. X#endif
  1186. X#ifdef os9
  1187. X#include <errno.h>
  1188. X#endif
  1189. X#ifdef amiga
  1190. X#include <errno.h>
  1191. X#endif
  1192. X
  1193. X#ifdef eon
  1194. X#define MEMSPACE    (16384)
  1195. X#endif
  1196. X
  1197. X
  1198. Xchar           *myname;
  1199. Xchar           *makefile;    /* The make file  */
  1200. X#ifdef eon
  1201. Xunsigned    memspace = MEMSPACE;
  1202. X#endif
  1203. X
  1204. XFILE           *ifd;        /* Input file desciptor  */
  1205. Xbool        domake = TRUE;    /* Go through the motions option  */
  1206. Xbool        ignore = FALSE; /* Ignore exit status option  */
  1207. Xbool        silent = FALSE; /* Silent option  */
  1208. Xbool        print = FALSE;    /* Print debuging information  */
  1209. Xbool        rules = TRUE;    /* Use inbuilt rules  */
  1210. Xbool        dotouch = FALSE;/* Touch files instead of making  */
  1211. Xbool        quest = FALSE;    /* Question up-to-dateness of file  */
  1212. X
  1213. X
  1214. Xvoid
  1215. Xmain(argc, argv)
  1216. X    register int    argc;
  1217. X    register char **argv;
  1218. X{
  1219. X    register char  *p;        /* For argument processing  */
  1220. X    int         estat = 0;    /* For question  */
  1221. X    register struct name *np;
  1222. X    void        prt(), circh();
  1223. X
  1224. X
  1225. X    myname = (argc-- < 1) ? "make" : *argv++;
  1226. X
  1227. X    while ((argc > 0) && (**argv == '-')) {
  1228. X    argc--;         /* One less to process    */
  1229. X    p = *argv++;        /* Now processing this one  */
  1230. X
  1231. X    while (*++p != '\0') {
  1232. X        switch (*p) {
  1233. X        case 'f':           /* Alternate file name  */
  1234. X        if (*++p == '\0') {
  1235. X            if (argc-- <= 0)
  1236. X            usage();
  1237. X            p = *argv++;
  1238. X        }
  1239. X        makefile = p;
  1240. X        goto end_of_args;
  1241. X#ifdef eon
  1242. X        case 'm':           /* Change space requirements  */
  1243. X        if (*++p == '\0') {
  1244. X            if (argc-- <= 0)
  1245. X            usage();
  1246. X            p = *argv++;
  1247. X        }
  1248. X        memspace = atoi(p);
  1249. X        goto end_of_args;
  1250. X#endif
  1251. X        case 'n':           /* Pretend mode  */
  1252. X        domake = FALSE;
  1253. X        break;
  1254. X        case 'i':           /* Ignore fault mode  */
  1255. X        ignore = TRUE;
  1256. X        break;
  1257. X        case 's':           /* Silent about commands  */
  1258. X        silent = TRUE;
  1259. X        break;
  1260. X        case 'p':
  1261. X        print = TRUE;
  1262. X        break;
  1263. X        case 'r':
  1264. X        rules = FALSE;
  1265. X        break;
  1266. X        case 't':
  1267. X        dotouch = TRUE;
  1268. X        break;
  1269. X        case 'q':
  1270. X        quest = TRUE;
  1271. X        break;
  1272. X        default:        /* Wrong option  */
  1273. X        usage();
  1274. X        }
  1275. X    }
  1276. Xend_of_args:;
  1277. X    }
  1278. X
  1279. X#ifdef amiga
  1280. X    if ((ifd = fopen("s:builtins.make", "r")) != (FILE *) 0) {
  1281. X    input(ifd);
  1282. X    fclose(ifd);
  1283. X    } else
  1284. X#endif
  1285. X    makerules();
  1286. X
  1287. X#ifdef eon
  1288. X    if (initalloc(memspace) == 0xffff)    /* Must get memory for alloc  */
  1289. X    fatal("Cannot initalloc memory");
  1290. X#endif
  1291. X
  1292. X    if (!makefile) {    /* If no file, then use default */
  1293. X    if ((ifd = fopen(DEFN1, "r")) == (FILE *) 0)
  1294. X#ifdef eon
  1295. X        if (errno != ER_NOTF)
  1296. X        fatal("Can't open %s; error %02x", DEFN1, errno);
  1297. X#endif
  1298. X#ifdef unix
  1299. X    if (errno != ENOENT)
  1300. X        fatal("Can't open %s; error %02x", DEFN1, errno);
  1301. X#endif
  1302. X#ifdef amiga
  1303. X    if (errno != ENOENT)
  1304. X        fatal("Can't open %s; error %02x", DEFN1, errno);
  1305. X#endif
  1306. X#ifdef DEFN2
  1307. X    if ((ifd == (FILE *) 0)
  1308. X        && ((ifd = fopen(DEFN2, "r")) == (FILE *) 0))
  1309. X        fatal("Can't open %s", DEFN2);
  1310. X#else
  1311. X    else
  1312. X        fatal("Can't open %s", DEFN1);
  1313. X#endif
  1314. X    } else if (strcmp(makefile, "-") == 0)      /* Can use stdin as makefile  */
  1315. X    ifd = stdin;
  1316. X    else if ((ifd = fopen(makefile, "r")) == (FILE *) 0)
  1317. X    fatal("Can't open %s", makefile);
  1318. X
  1319. X    setmacro("$", "$");
  1320. X
  1321. X    while (argc && (p = index(*argv, '='))) {
  1322. X    char        c;
  1323. X
  1324. X    c = *p;
  1325. X    *p = '\0';
  1326. X    setmacro(*argv, p + 1);
  1327. X    *p = c;
  1328. X
  1329. X    argv++;
  1330. X    argc--;
  1331. X    }
  1332. X
  1333. X    input(ifd);         /* Input all the gunga    */
  1334. X    fclose(ifd);        /* Finished with makefile  */
  1335. X    lineno = 0;         /* Any calls to error now print no line
  1336. X                 * number */
  1337. X
  1338. X    if (print)
  1339. X    prt();            /* Print out structures  */
  1340. X
  1341. X    np = newname(".SILENT");
  1342. X    if (np->n_flag & N_TARG)
  1343. X    silent = TRUE;
  1344. X
  1345. X    np = newname(".IGNORE");
  1346. X    if (np->n_flag & N_TARG)
  1347. X    ignore = TRUE;
  1348. X
  1349. X    precious();
  1350. X
  1351. X    if (!firstname)
  1352. X    fatal("No targets defined");
  1353. X
  1354. X    circh();            /* Check circles in target definitions    */
  1355. X
  1356. X    if (!argc)
  1357. X    estat = make(firstname, 0);
  1358. X    else
  1359. X    while (argc--) {
  1360. X        if (!print && !silent && strcmp(*argv, "love") == 0)
  1361. X        printf("Not war!\n");
  1362. X        estat |= make(newname(*argv++), 0);
  1363. X    }
  1364. X
  1365. X    if (quest)
  1366. X    exit(estat);
  1367. X    else
  1368. X    exit(0);
  1369. X}
  1370. X
  1371. X
  1372. Xusage()
  1373. X{
  1374. X    fprintf(stderr, "Usage: %s [-f makefile] [-inpqrst] [macro=val ...] [target(s) ...]\n", myname);
  1375. X    exit(1);
  1376. X}
  1377. X
  1378. X
  1379. Xvoid
  1380. Xfatal(msg, a1, a2, a3, a4, a5, a6)
  1381. X    char       *msg;
  1382. X{
  1383. X    fprintf(stderr, "%s: ", myname);
  1384. X    fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
  1385. X    fputc('\n', stderr);
  1386. X    exit(1);
  1387. X}
  1388. X
  1389. X#ifdef amiga    /*OIS*0.80*/
  1390. X
  1391. X/*
  1392. X * The Amiga case-insensitive filing system needs a case-insensitive
  1393. X * filename comparison. Since strcmp() in this make is only applied to
  1394. X * filenames, we simply replace it.
  1395. X * Unfortunately, this also affects .PRECIOUS, .IGNORE, .SUFFIXES and
  1396. X * .SILENT. Therefore, we need a hack, but that costs space, so we don't.
  1397. X */
  1398. X
  1399. Xint lower(c)
  1400. Xregister unsigned int c;
  1401. X{
  1402. X    if (c >= 'A' && c <= 'Z')
  1403. X    return c - 'A' + 'a';
  1404. X
  1405. X    return c;
  1406. X}
  1407. X
  1408. Xint stricmp(first, second)    /* Case-insensitive strcmp() */
  1409. Xregister unsigned char *first, *second;
  1410. X{
  1411. X    register int cmp;
  1412. X
  1413. X    while (!(cmp = lower(*first++) - lower(*second++))) {
  1414. X    if (!first[-1]) return 0;
  1415. X    }
  1416. X
  1417. X    return (cmp < 0) ? -1 : 1;
  1418. X}
  1419. X
  1420. X/* Manx and PDC allow you to leave out Workbench code */
  1421. X
  1422. X_wb_parse(){}
  1423. X
  1424. X#endif
  1425. END_OF_FILE
  1426. if test 5539 -ne `wc -c <'main.c'`; then
  1427.     echo shar: \"'main.c'\" unpacked with wrong size!
  1428. fi
  1429. # end of 'main.c'
  1430. fi
  1431. if test -f 'make.n' -a "${1}" != "-c" ; then 
  1432.   echo shar: Will not clobber existing file \"'make.n'\"
  1433. else
  1434. echo shar: Extracting \"'make.n'\" \(7344 characters\)
  1435. sed "s/^X//" >'make.n' <<'END_OF_FILE'
  1436. X.so an
  1437. X.de HP
  1438. X.ti -5
  1439. X.en
  1440. X.TH MAKE 1 "AMIGA Programmer's Manual"
  1441. X.SH NAME
  1442. Xmake - maintain program groups
  1443. X.SH SYNTAX
  1444. Xmake [ -f makefile ] [ option ] ... file ...
  1445. X.SH DESCRIPTION
  1446. X.I Make
  1447. Xexecutes commands in
  1448. X.I makefile
  1449. Xto update one or more target
  1450. X.I names. Name
  1451. Xis typically a program. If no -f option
  1452. Xis present, `makefile' and `Makefile' are tried in order.
  1453. XIf
  1454. X.I makefile
  1455. Xis `-', the standard input is taken. More than one -f option may appear.
  1456. X
  1457. X.I Make
  1458. Xupdates a target if it depends on prerequisite files that have been
  1459. Xmodified since the target was last modified, or if the target does not
  1460. Xexist.
  1461. X
  1462. X.I Makefile
  1463. Xcontains a sequence of entries that specify dependencies. The first line of
  1464. Xan entry is a blank-separated list of targets, then a colon, then a list of
  1465. Xprerequisite files. Text following a semicolon, and all following lines
  1466. Xthat begin with a tab, are shell commands to be executed to update the
  1467. Xtarget. If a name appears on the left of more than one `colon' line, then
  1468. Xit depends on all of the names on the right of the colon on those lines,
  1469. Xbut only one command sequence may be specified for it. If a name appears on
  1470. Xa line with a double colon :: then the command sequence following that line
  1471. Xis performed only if the name is out of date with respect to the names to
  1472. Xthe right of the double colon, and is not affected by other double colon
  1473. Xlines on which that name may appear.
  1474. X
  1475. XTwo special forms of a name are recognized. A name like
  1476. X.I a(b)
  1477. Xmeans the file named
  1478. X.I b
  1479. Xstored in the archive named
  1480. X.I a.
  1481. XA name like
  1482. X.I a((b))
  1483. Xmeans the file stored in archive a containing the entry point
  1484. X.I b.
  1485. X
  1486. XSharp and newline surround comments.
  1487. X
  1488. XThe following makefile says that `pgm' depends on two files `a.o' and
  1489. X`b.o', and that they in turn depend on `.c' files and a common file `incl'.
  1490. X
  1491. X        pgm: a.o b.o
  1492. X                cc a.o b.o -lm -o pgm
  1493. X        a.o: incl a.c
  1494. X                cc -c a.c
  1495. X        b.o: incl b.c
  1496. X                cc -c b.c
  1497. X
  1498. X.I Makefile
  1499. Xentries of the form
  1500. X
  1501. X        string1 = string2
  1502. X
  1503. Xare macro definitions. Subsequent appearances of
  1504. X.I $(string1)
  1505. Xor
  1506. X.I ${string1}
  1507. Xare replaced by
  1508. X.I string2.
  1509. XIf
  1510. X.I string1
  1511. Xis a single character, the parentheses or braces are optional.
  1512. X
  1513. X.I Make
  1514. Xinfers prerequisites for files for which
  1515. X.I makefile
  1516. Xgives no construction commands. For example, a `.c' file may be inferred as
  1517. Xprerequisite for a `.o' file and be compiled to produce the `.o' file. Thus
  1518. Xthe preceding example can be done more briefly:
  1519. X
  1520. X        pgm: a.o b.o
  1521. X                cc a.o b.o -lm -o pgm
  1522. X        a.o b.o: incl
  1523. X
  1524. XPrerequisites are inferred according to selected suffixes listed as the
  1525. X`prerequisites' for the special name `.SUFFIXES'; multiple lists
  1526. Xaccumulate; an empty list clears what came before. Order is significant;
  1527. Xthe first possible name for which both a file and a rule as described in
  1528. Xthe next paragraph exist is inferred. The default list is
  1529. X
  1530. X        .SUFFIXES: .out .o .c .e .r .f .y .l .s .p
  1531. X
  1532. XThe rule to create a file with suffix
  1533. X.I s2
  1534. Xthat depends on a similarly named file with suffix
  1535. X.I s1
  1536. Xis specified as an entry for the `target'
  1537. X.I s1s2.
  1538. XIn such an entry, the special macro $* stands for the target name with
  1539. Xsuffix deleted, $@@ for the full target name, $< for the complete list of
  1540. Xprerequisites, and $? for the list of prerequisites that are out of date.
  1541. XFor example, a rule for making optimized `.o' files from `.c' files is
  1542. X
  1543. X        .c.o: ; cc -c -O -o $@@ $*.c
  1544. X
  1545. XCertain macros are used by the default inference rules to communicate
  1546. Xoptional arguments to any resulting compilations. In particular, `CFLAGS'
  1547. Xis used for
  1548. X.I cc(1)
  1549. Xoptions, `FFLAGS' for
  1550. X.I f77(1)
  1551. Xoptions, `PFLAGS' for
  1552. X.I pc(1)
  1553. Xoptions, and `LFLAGS' and `YFLAGS' for
  1554. X.I lex
  1555. Xand
  1556. X.I yacc(1)
  1557. Xoptions. In addition, the macro `MFLAGS' is filled in with the initial
  1558. Xcommand line options supplied to
  1559. X.I make.
  1560. XThis simplifies maintaining a hierarchy of makefiles as one may then invoke
  1561. X.I make
  1562. Xon makefiles in subdirectories and pass along useful options such as -k.
  1563. X
  1564. XCommand lines are executed one at a time, each by its own shell. A line is
  1565. Xprinted when it is executed unless the special target `.SILENT' is in
  1566. X.I makefile,
  1567. Xor the first character of the command is `@@'.
  1568. X
  1569. XCommands returning nonzero status (see
  1570. X.I intro(1))
  1571. Xcause
  1572. X.I make
  1573. Xto terminate unless the special target `.IGNORE' is in
  1574. X.I makefile
  1575. Xor the command begins with <tab><hyphen>.
  1576. X
  1577. XInterrupt and quit cause the target to be deleted unless the target is a
  1578. Xdirectory or depends on the special name `.PRECIOUS'.
  1579. X
  1580. XOther options:
  1581. X
  1582. X.RS +5
  1583. X.HP
  1584. X-i@tEquivalent to the special entry `.IGNORE:'.
  1585. X
  1586. X.HP
  1587. X-k@tWhen a command returns nonzero status, abandon work on the current
  1588. Xentry, but continue on branches that do not depend on the current entry.
  1589. X
  1590. X.HP
  1591. X-n@tTrace and print, but do not execute the commands needed to update the
  1592. Xtargets.
  1593. X
  1594. X.HP
  1595. X-t@tTouch, i.e. update the modified date of targets, without executing any
  1596. Xcommands.
  1597. X
  1598. X.HP
  1599. X-r@tEquivalent to an initial special entry `.SUFFIXES:' with no list.
  1600. X
  1601. X.HP
  1602. X-s@tEquivalent to the special entry `.SILENT:'.
  1603. X
  1604. X.HP
  1605. X-q@tQuestion up-to-dateness of target. Return exit status 1 if not;
  1606. Xotherwise, return 0.
  1607. X
  1608. X.HP
  1609. X-r@tDon't use built-in rules.
  1610. X.RE
  1611. X.SH FILES
  1612. Xmakefile, Makefile
  1613. X.SH "SEE ALSO"
  1614. Xsh(1), touch(1), f77(1), pc(1)
  1615. X.br
  1616. XS. I. Feldman
  1617. X.I "Make - A Program for Maintaining Computer Programs"
  1618. X.SH BUGS
  1619. XSome commands return nonzero status inappropriately. Use -i
  1620. Xto overcome the difficulty.
  1621. XCommands that are directly executed by the shell, notably
  1622. X.I cd(1),
  1623. Xare ineffectual across newlines in
  1624. X.I make.
  1625. X.SH "AMIGA VERSION"
  1626. XNot all of the above applies to the Amiga version of
  1627. X.I make.
  1628. XIn particular, the default rules and suffixes are different.
  1629. X
  1630. XOmissions:
  1631. X.br
  1632. XLibraries and the related notation are not implemented.
  1633. X.br
  1634. XThe -k option is not supported.
  1635. X.br
  1636. XThe `;' construct is not implemented.
  1637. X.br
  1638. XThe remarks related to
  1639. X.I MFLAGS, lex(1), yacc(1), f77(1)
  1640. Xand
  1641. X.I pc(1)
  1642. Xdo not apply.
  1643. X.br
  1644. X$< and $? are not exactly as specified: $< is ONE prerequisite that is out
  1645. Xof date (including path name), and $? is ALL prerequisites (without path
  1646. Xnames).
  1647. X
  1648. XAdditions:
  1649. X.br
  1650. XIf a file
  1651. X.I s:builtins.make
  1652. Xexists, this file is used instead of the built-in rules.
  1653. X.br
  1654. XFilenames are not case-significant. Unfortunately, this also applies to the
  1655. Xspecial target names .PRECIOUS, .IGNORE and .SILENT. These can also be
  1656. Xspecified as .Precious, or .iGnOrE.
  1657. X.br
  1658. X.I Cd
  1659. Xcommands are effective.
  1660. X.br
  1661. XComment characters (#) may be escaped with a backslash (\).
  1662. X.br
  1663. XAt most 1 colon is allowed in a target file name (for including device
  1664. Xnames). In that case, the trailing colon must follow the target name
  1665. Ximmediately, without any intervening white space. Spaces in the names are
  1666. Xnot allowed.
  1667. X.br
  1668. XA new special target name has been added:
  1669. X.it "@.PATH.
  1670. XAny prerequisite names for
  1671. X.it "@.PATH
  1672. Xare used for finding source files for implicit rules. You name one or more
  1673. Xdirectories, and if the source file for an implicit rule cannot be found
  1674. Xin the current directory, each of the the given pathnames is prepended (in
  1675. Xthe order given) to the source name, until the file is found.
  1676. X
  1677. XFor instance, the Makefile
  1678. X
  1679. X        .PATH:  src/ include/ src/old
  1680. X
  1681. X        pgm:    pgm.o
  1682. X
  1683. Xwill look (according to the .c.o rule) for pgm.c, src/pgm.c, include/pgm.c
  1684. Xand src/oldpgm.c, in that order. Of course, due to other implicit rules,
  1685. Xother files (with other suffixes) may be tried as well.
  1686. END_OF_FILE
  1687. if test 7344 -ne `wc -c <'make.n'`; then
  1688.     echo shar: \"'make.n'\" unpacked with wrong size!
  1689. fi
  1690. # end of 'make.n'
  1691. fi
  1692. if test -f 'reader.c' -a "${1}" != "-c" ; then 
  1693.   echo shar: Will not clobber existing file \"'reader.c'\"
  1694. else
  1695. echo shar: Extracting \"'reader.c'\" \(2183 characters\)
  1696. sed "s/^X//" >'reader.c' <<'END_OF_FILE'
  1697. X/*
  1698. X *    Read in makefile
  1699. X */
  1700. X
  1701. X
  1702. X#include <stdio.h>
  1703. X#include <ctype.h>
  1704. X#include "h.h"
  1705. X
  1706. X
  1707. Xint        lineno;
  1708. X
  1709. X
  1710. X/*
  1711. X *    Syntax error handler.  Print message, with line number, and exits.
  1712. X */
  1713. Xvoid
  1714. Xerror(msg, a1, a2, a3)
  1715. X    char       *msg;
  1716. X{
  1717. X    fprintf(stderr, "%s: ", myname);
  1718. X    fprintf(stderr, msg, a1, a2, a3);
  1719. X    if (lineno)
  1720. X    fprintf(stderr, " near line %d", lineno);
  1721. X    fputc('\n', stderr);
  1722. X    exit(1);
  1723. X}
  1724. X
  1725. X
  1726. X/*
  1727. X *    Read a line into the supplied string of length LZ.  Remove
  1728. X *    comments, ignore blank lines. Deal with quoted (\) #, and
  1729. X *    quoted newlines.  If EOF return TRUE.
  1730. X */
  1731. Xbool
  1732. Xgetline(str, fd)
  1733. X    char       *str;
  1734. X    FILE       *fd;
  1735. X{
  1736. X    register char  *p;
  1737. X    register char  *q;        /*OIS*0.80*/
  1738. X    int         pos = 0;
  1739. X
  1740. X
  1741. X    for (;;) {
  1742. X    if (fgets(str + pos, LZ - pos, fd) == (char *) 0)
  1743. X        return TRUE;    /* EOF    */
  1744. X
  1745. X    lineno++;
  1746. X
  1747. X    if ((p = index(str + pos, '\n')) == (char *) 0)
  1748. X        error("Line too long");
  1749. X
  1750. X    if (p[-1] == '\\') {
  1751. X        register char space; /*OIS*0.80*/
  1752. X        /* p[-1] = '\n';  */ /*OIS*0.80*/
  1753. X        /* Skip the leading spaces of the next line */
  1754. X        while (space = getc(fd), space == ' ' || space == '\t');
  1755. X        p[-1] = space;
  1756. X        if (space != '\n') {
  1757. X        pos = p - str;
  1758. X        continue;   /* read next line */
  1759. X        }
  1760. X    }
  1761. X    p = str;
  1762. X    while (((q = index(p, '#')) != (char *) 0) &&
  1763. X           (p != q) && (q[-1] == '\\')) {
  1764. X        char       *a;
  1765. X
  1766. X        a = q - 1;        /* Del \ chr; move rest back  */
  1767. X        p = q;
  1768. X        while (*a++ = *q++);
  1769. X    }
  1770. X    if (q != (char *) 0) {
  1771. X        q[0] = '\n';
  1772. X        q[1] = '\0';
  1773. X    }
  1774. X    p = str;
  1775. X    while (isspace(*p))    /* Checking for blank line */
  1776. X        p++;
  1777. X
  1778. X    if (*p != '\0')
  1779. X        return FALSE;
  1780. X    pos = 0;
  1781. X    }
  1782. X}
  1783. X
  1784. X
  1785. X/*
  1786. X *    Get a word from the current line, surounded by white space.
  1787. X *    return a pointer to it. String returned has no white spaces
  1788. X *    in it.
  1789. X */
  1790. Xchar           *
  1791. Xgettok(ptr)
  1792. X    register char  **ptr;    /*OIS*0.80*/
  1793. X{
  1794. X    register char  *p;
  1795. X
  1796. X
  1797. X    while (isspace(**ptr))    /* Skip spaces    */
  1798. X    (*ptr)++;
  1799. X
  1800. X    if (**ptr == '\0')          /* Nothing after spaces  */
  1801. X    return NULL;
  1802. X
  1803. X    p = *ptr;            /* word starts here  */
  1804. X
  1805. X    while ((**ptr != '\0') && (!isspace(**ptr)))
  1806. X    (*ptr)++;        /* Find end of word  */
  1807. X
  1808. X    *(*ptr)++ = '\0';           /* Terminate it  */
  1809. X
  1810. X    return (p);
  1811. X}
  1812. END_OF_FILE
  1813. if test 2183 -ne `wc -c <'reader.c'`; then
  1814.     echo shar: \"'reader.c'\" unpacked with wrong size!
  1815. fi
  1816. # end of 'reader.c'
  1817. fi
  1818. if test -f 'rules.c' -a "${1}" != "-c" ; then 
  1819.   echo shar: Will not clobber existing file \"'rules.c'\"
  1820. else
  1821. echo shar: Extracting \"'rules.c'\" \(8196 characters\)
  1822. sed "s/^X//" >'rules.c' <<'END_OF_FILE'
  1823. X/*
  1824. X *    Control of the implicit suffix rules
  1825. X */
  1826. X
  1827. X
  1828. X#include "h.h"
  1829. X#ifndef NULL
  1830. X#define NULL ((void *) 0)
  1831. X#endif
  1832. X
  1833. X/*
  1834. X * Return a pointer to the suffix of a name
  1835. X */
  1836. Xchar           *
  1837. Xsuffix(name)
  1838. X    char       *name;
  1839. X{
  1840. X    return rindex(name, '.');
  1841. X}
  1842. X
  1843. X
  1844. X/*
  1845. X *    Dynamic dependency.  This routine applies the suffis rules
  1846. X *    to try and find a source and a set of rules for a missing
  1847. X *    target.  If found, np is made into a target with the implicit
  1848. X *    source name, and rules.  Returns TRUE if np was made into
  1849. X *    a target.
  1850. X */
  1851. Xbool
  1852. Xdyndep(np, pbasename, pinputname)
  1853. X    struct name    *np;
  1854. X    char      **pbasename;    /*  Name without suffix  */
  1855. X    char      **pinputname;
  1856. X{
  1857. X    register char  *p;
  1858. X    register char  *q;
  1859. X    register char  *suff;    /* Old suffix  */
  1860. X    register char  *basename;    /* Name without suffix    */
  1861. X    struct name    *op;     /* New dependent  */
  1862. X    struct name    *sp;     /* Suffix  */
  1863. X    struct line    *lp;
  1864. X    struct depend  *dp;
  1865. X    struct name    *pathnp;    /* .PATH */
  1866. X    struct line    *pathlp;
  1867. X    struct depend  *pathdp;
  1868. X    struct depend  *pathdp1;
  1869. X    char       *newsuff;
  1870. X    char       *path;
  1871. X    void        modtime();
  1872. X
  1873. X
  1874. X    p = str1;
  1875. X    q = np->n_name;
  1876. X    if (!(suff = suffix(q)))
  1877. X    return FALSE;        /* No suffix */
  1878. X    while (q < suff)
  1879. X    *p++ = *q++;
  1880. X    *p = '\0';
  1881. X    if ((*pbasename = basename = malloc(strlen(str1)+1)) == NULL)
  1882. X    fatal("No memory for basename");
  1883. X    strcpy(*pbasename, str1);
  1884. X
  1885. X    if (!((sp = newname(".SUFFIXES"))->n_flag & N_TARG))
  1886. X    return FALSE;
  1887. X
  1888. X    if (!((pathnp = newname(".PATH"))->n_flag & N_TARG))
  1889. X    pathnp = NULL;
  1890. X
  1891. X    if ((pathnp) && (pathlp = pathnp->n_line))
  1892. X    pathdp = pathlp->l_dep;
  1893. X    else
  1894. X    pathdp = NULL;
  1895. X
  1896. X    for (lp = sp->n_line; lp; lp = lp->l_next)
  1897. X    for (dp = lp->l_dep; dp; dp = dp->d_next) {
  1898. X        newsuff = dp->d_name->n_name;   /* .c .o .asm etc */
  1899. X        if (strlen(suff) + strlen(newsuff) + 1 >= LZ)
  1900. X        fatal("Suffix rule too long");
  1901. X        p = str1;
  1902. X        q = newsuff;
  1903. X        while (*p++ = *q++);
  1904. X        p--;
  1905. X        q = suff;
  1906. X        while (*p++ = *q++);
  1907. X        sp = newname(str1);     /* Form for example .c.o */
  1908. X        if (sp->n_flag & N_TARG) {
  1909. X        path = "";
  1910. X        pathdp1 = pathdp;
  1911. X    nextpath:
  1912. X        p = str1;
  1913. X        if (strlen(path) + strlen(basename) + strlen(newsuff) + 2 >= LZ)
  1914. X            fatal("Implicit name too long");
  1915. X        q = path;
  1916. X        while (*p++ = *q++);    /* copy path */
  1917. X        p--;
  1918. X        q = basename;
  1919. X        while (*p++ = *q++);    /* copy basename */
  1920. X        p--;
  1921. X        q = newsuff;
  1922. X        while (*p++ = *q++);    /* copy new suffix */
  1923. X        op = newname(str1);
  1924. X        if (!op->n_line && !op->n_time)
  1925. X            modtime(op);
  1926. X        if (op->n_line || op->n_time) {     /* file exists? */
  1927. X            dp = newdep(op, NULL);
  1928. X            newline(np, dp, sp->n_line->l_cmd, 0);
  1929. X            *pinputname = op->n_name;    /* $< = path/basename.suffix */
  1930. X            return TRUE;
  1931. X        } else {
  1932. X            delname(op);        /* Forget non-existing file */
  1933. X            if (pathdp1) {      /* But is there a path? */
  1934. X            path = pathdp1->d_name->n_name;
  1935. X            pathdp1 = pathdp1->d_next;
  1936. X            goto nextpath;
  1937. X            }
  1938. X        }
  1939. X        }
  1940. X    }
  1941. X    return FALSE;
  1942. X}
  1943. X
  1944. X
  1945. X/*
  1946. X *    Make the default rules
  1947. X */
  1948. Xvoid
  1949. Xmakerules()
  1950. X{
  1951. X    register struct cmd     *cp;    /*OIS*0.80*/
  1952. X    register struct name    *np;    /*OIS*0.80*/
  1953. X    register struct depend  *dp;    /*OIS*0.80*/
  1954. X
  1955. X
  1956. X#ifdef eon
  1957. X    setmacro("BDSCC", "asm");
  1958. X    /* setmacro("BDSCFLAGS", "");        */
  1959. X    cp = newcmd("$(BDSCC) $(BDSCFLAGS) -n $<", 0);
  1960. X    np = newname(".c.o");
  1961. X    newline(np, 0, cp, 0);
  1962. X
  1963. X    setmacro("CC", "c");
  1964. X    setmacro("CFLAGS", "-O");
  1965. X    cp = newcmd("$(CC) $(CFLAGS) -c $<", 0);
  1966. X    np = newname(".c.obj");
  1967. X    newline(np, 0, cp, 0);
  1968. X
  1969. X    setmacro("M80", "asm -n");
  1970. X    /* setmacro("M80FLAGS", "");         */
  1971. X    cp = newcmd("$(M80) $(M80FLAGS) $<", 0);
  1972. X    np = newname(".mac.o");
  1973. X    newline(np, 0, cp, 0);
  1974. X
  1975. X    setmacro("AS", "zas");
  1976. X    /* setmacro("ASFLAGS", "");  */
  1977. X    cp = newcmd("$(ZAS) $(ASFLAGS) -o $@ $<", 0);
  1978. X    np = newname(".as.obj");
  1979. X    newline(np, 0, cp, 0);
  1980. X
  1981. X    np = newname(".as");
  1982. X    dp = newdep(np, 0);
  1983. X    np = newname(".obj");
  1984. X    dp = newdep(np, dp);
  1985. X    np = newname(".c");
  1986. X    dp = newdep(np, dp);
  1987. X    np = newname(".o");
  1988. X    dp = newdep(np, dp);
  1989. X    np = newname(".mac");
  1990. X    dp = newdep(np, dp);
  1991. X    np = newname(".SUFFIXES");
  1992. X    newline(np, dp, 0, 0);
  1993. X#endif
  1994. X
  1995. X/*
  1996. X *    Some of the UNIX implicit rules
  1997. X */
  1998. X#ifdef unix
  1999. X    setmacro("CC", "cc");
  2000. X    setmacro("CFLAGS", "-O");
  2001. X#ifdef MINIXPC
  2002. X    cp = newcmd("$(CC) $(CFLAGS) -S $<", (struct cmd *)0);
  2003. X    np = newname(".c.s");
  2004. X#else
  2005. X    cp = newcmd("$(CC) $(CFLAGS) -c $<", (struct cmd *)0);
  2006. X    np = newname(".c.o");
  2007. X#endif MINIXPC
  2008. X    newline(np, (struct depend *)0, cp, 0);
  2009. X
  2010. X    setmacro("AS", "as");
  2011. X    cp = newcmd("$(AS) -o $@ $<", (struct cmd *)0);
  2012. X    np = newname(".s.o");
  2013. X    newline(np, (struct depend *)0, cp, 0);
  2014. X
  2015. X    setmacro("YACC", "yacc");
  2016. X    /*        setmacro("YFLAGS", ""); */
  2017. X    cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
  2018. X    cp = newcmd("mv y.tab.c $@", cp);
  2019. X    np = newname(".y.c");
  2020. X    newline(np, (struct depend *)0, cp, 0);
  2021. X
  2022. X    cp = newcmd("$(YACC) $(YFLAGS) $<", (struct cmd *)0);
  2023. X#ifdef MINIXPC
  2024. X    cp = newcmd("$(CC) $(CFLAGS) -S y.tab.c", cp);
  2025. X    cp = newcmd("mv y.tab.s $@", cp);
  2026. X    np = newname(".y.s");
  2027. X#else
  2028. X    cp = newcmd("$(CC) $(CFLAGS) -c y.tab.c", cp);
  2029. X    cp = newcmd("mv y.tab.o $@", cp);
  2030. X    np = newname(".y.o");
  2031. X#endif MINIXPC
  2032. X    cp = newcmd("rm y.tab.c", cp);
  2033. X    newline(np, (struct depend *)0, cp, 0);
  2034. X
  2035. X    setmacro("FLEX", "flex");
  2036. X    cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
  2037. X    cp = newcmd("mv lex.yy.c $@", cp);
  2038. X    np = newname(".l.c");
  2039. X    newline(np, (struct depend *)0, cp, 0);
  2040. X
  2041. X    cp = newcmd("$(FLEX) $(FLEX_FLAGS) $<", (struct cmd *)0);
  2042. X#ifdef MINIXPC
  2043. X    cp = newcmd("$(CC) $(CFLAGS) -S lex.yy.s", cp);
  2044. X    cp = newcmd("mv lex.yy.s $@", cp);
  2045. X    np = newname(".l.s");
  2046. X#else
  2047. X    cp = newcmd("$(CC) $(CFLAGS) -c lex.yy.c", cp);
  2048. X    cp = newcmd("mv lex.yy.o $@", cp);
  2049. X    np = newname(".l.o");
  2050. X#endif MINIXPC
  2051. X    cp = newcmd("rm lex.yy.c", cp);
  2052. X    newline(np, (struct depend *)0, cp, 0);
  2053. X
  2054. X    np = newname(".o");
  2055. X    dp = newdep(np, (struct depend *)0);
  2056. X    np = newname(".s");
  2057. X    dp = newdep(np, dp);
  2058. X    np = newname(".c");
  2059. X    dp = newdep(np, dp);
  2060. X    np = newname(".y");
  2061. X    dp = newdep(np, dp);
  2062. X    np = newname(".l");
  2063. X    dp = newdep(np, dp);
  2064. X    np = newname(".SUFFIXES");
  2065. X    newline(np, dp, (struct cmd *)0, 0);
  2066. X#endif
  2067. X
  2068. X#ifdef os9
  2069. X/*
  2070. X *    Fairlight use an enhanced version of the C sub-system.
  2071. X *    They have a specialised macro pre-processor.
  2072. X */
  2073. X    setmacro("CC", "cc");
  2074. X    setmacro("CFLAGS", "-z");
  2075. X    cp = newcmd("$(CC) $(CFLAGS) -r $<", 0);
  2076. X
  2077. X    np = newname(".c.r");
  2078. X    newline(np, 0, cp, 0);
  2079. X    np = newname(".ca.r");
  2080. X    newline(np, 0, cp, 0);
  2081. X    np = newname(".a.r");
  2082. X    newline(np, 0, cp, 0);
  2083. X    np = newname(".o.r");
  2084. X    newline(np, 0, cp, 0);
  2085. X    np = newname(".mc.r");
  2086. X    newline(np, 0, cp, 0);
  2087. X    np = newname(".mca.r");
  2088. X    newline(np, 0, cp, 0);
  2089. X    np = newname(".ma.r");
  2090. X    newline(np, 0, cp, 0);
  2091. X    np = newname(".mo.r");
  2092. X    newline(np, 0, cp, 0);
  2093. X
  2094. X    np = newname(".r");
  2095. X    dp = newdep(np, 0);
  2096. X    np = newname(".mc");
  2097. X    dp = newdep(np, dp);
  2098. X    np = newname(".mca");
  2099. X    dp = newdep(np, dp);
  2100. X    np = newname(".c");
  2101. X    dp = newdep(np, dp);
  2102. X    np = newname(".ca");
  2103. X    dp = newdep(np, dp);
  2104. X    np = newname(".ma");
  2105. X    dp = newdep(np, dp);
  2106. X    np = newname(".mo");
  2107. X    dp = newdep(np, dp);
  2108. X    np = newname(".o");
  2109. X    dp = newdep(np, dp);
  2110. X    np = newname(".a");
  2111. X    dp = newdep(np, dp);
  2112. X    np = newname(".SUFFIXES");
  2113. X    newline(np, dp, 0, 0);
  2114. X#endif
  2115. X
  2116. X#ifdef amiga
  2117. X
  2118. X#ifdef pdc    /*OIS*0.80*/
  2119. X    static char ccx_c[] = "ccx -c";
  2120. X
  2121. X    setmacro("CC", ccx_c);
  2122. X#else
  2123. X    setmacro("CC", "cc");
  2124. X#endif
  2125. X    cp = newcmd("$(CC) $(CFLAGS) $<", NULL);
  2126. X    np = newname(".c.o");
  2127. X    newline(np, NULL, cp, 0);
  2128. X
  2129. X#ifdef pdc    /*OIS*0.80*/
  2130. X    setmacro("AS", ccx_c);
  2131. X    cp = newcmd("$(AS) $(AFLAGS) $<", NULL);        /*OIS*0.80*/
  2132. X#else
  2133. X    setmacro("AS", "as");
  2134. X    cp = newcmd("$(AS) $(AFLAGS) -o $@ $<", NULL);  /*OIS*0.80*/
  2135. X#endif
  2136. X    np = newname(".s.o");
  2137. X    newline(np, NULL, cp, NULL);
  2138. X
  2139. X    np = newname(".o");
  2140. X    dp = newdep(np, NULL);
  2141. X    np = newname(".s");
  2142. X    dp = newdep(np, dp);
  2143. X    np = newname(".c");
  2144. X    dp = newdep(np, dp);
  2145. X    np = newname(".SUFFIXES");
  2146. X    newline(np, dp, NULL, 0);
  2147. X#endif
  2148. X}
  2149. END_OF_FILE
  2150. if test 8196 -ne `wc -c <'rules.c'`; then
  2151.     echo shar: \"'rules.c'\" unpacked with wrong size!
  2152. fi
  2153. # end of 'rules.c'
  2154. fi
  2155. echo shar: End of archive 1 \(of 2\).
  2156. cp /dev/null ark1isdone
  2157. MISSING=""
  2158. for I in 1 2 ; do
  2159.     if test ! -f ark${I}isdone ; then
  2160.     MISSING="${MISSING} ${I}"
  2161.     fi
  2162. done
  2163. if test "${MISSING}" = "" ; then
  2164.     echo You have unpacked both archives.
  2165.     rm -f ark[1-9]isdone
  2166. else
  2167.     echo You still need to unpack the following archives:
  2168.     echo "        " ${MISSING}
  2169. fi
  2170. ##  End of shell archive.
  2171. exit 0
  2172. -- 
  2173. Submissions to comp.sources.amiga and comp.binaries.amiga should be sent to:
  2174.     amiga@cs.odu.edu    
  2175. or    amiga@xanth.cs.odu.edu    ( obsolescent mailers may need this address )
  2176. or    ...!uunet!xanth!amiga    ( very obsolescent mailers need this address )
  2177.  
  2178. Comments, questions, and suggestions s should be addressed to ``amiga-request''
  2179. (only use ``amiga'' for submissions) at the above addresses.
  2180.